package edu.hda.pt.client.connections.rmi;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import edu.hda.pt.client.connections.PTClientRMI;
import edu.hda.pt.utils.connections.rmi.PTClientRMICallbackI;
import edu.hda.pt.utils.connections.rmi.StreamingData;

/**
 * Call back handler for RMI client
 * 
 * @author Marc Hammerton
 * 
 */
public class RMICallbackStreamHandler extends UnicastRemoteObject implements
		PTClientRMICallbackI {

	/**
	 * ID for the serialization
	 */
	private static final long serialVersionUID = -8151014380441134167L;

	private PTClientRMI client;

	/**
	 * Constructor setting the client object
	 * 
	 * @param client
	 *            - client object
	 * @throws RemoteException
	 */
	public RMICallbackStreamHandler(PTClientRMI client) throws RemoteException {
		super();
		this.client = client;
	}

	/**
	 * Call back method for streams. It informs the client when a message is
	 * received.
	 * 
	 * @see edu.hda.pt.utils.connections.rmi.PTClientRMICallbackI#handleStream(edu
	 *      .hda.pt.utils.connections.rmi.StreamingData)
	 */
	@Override
	public void handleStream(StreamingData data) throws RemoteException {
		synchronized (client) {
			client.notify();
		}
	}

}
